package ai.esc.speedy.admin.user.interfaces.controller;

import ai.esc.speedy.admin.user.api.UpdateAppUserPermissionsCommand;
import ai.esc.speedy.common.base.BaseController;
import ai.esc.speedy.common.base.Message;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Set;

/**
 * 系统用户接口
 *
 * @author Rubin
 * @version v1 2020/3/3 19:07
 */
@RestController
@RequestMapping("/user")
public class PassportController extends BaseController {

    /**
     * 授权
     *
     * @param userId
     * @param auth
     * @return
     */
    @PutMapping("/authorization/{userId}/")
    public Message authorization(@PathVariable String userId,
                                 @RequestBody Map<String, Set<String>> auth) {
        return Message.builder().ok()
                .data(commandGateway.send(
                        new UpdateAppUserPermissionsCommand(userId, auth.get("permissions"), auth.get("resources"))).join())
                .build();
    }

    // 添加权限
    // createPermission

    /*
     * 修改权限
     */


    // 删除权限

    // 添加资源
    // 修改资源
    // 删除资源
}
